package dryven.model.binding.form;

import java.util.ArrayList;
import java.util.Collection;

import dryven.model.binding.fieldset.Field;
import dryven.model.binding.fieldset.FieldGroup;
import dryven.util.json.dryvenjson.JSON;

public class FormGroup {
	
	private FieldGroup _group;
	private Form _form;
	private Iterable<FormBinding> _bindings;
	
	public FormGroup(FieldGroup group, Form form) {
		super();
		_group = group;
		_form = form;
	}

	@JSON
	public String getTitle() {return _group.getNameKey();}
	
	@JSON
	public Iterable<FormBinding> getBindings() {
		if(_bindings==null) {
			Collection<FormBinding> bindings = new ArrayList<FormBinding>();
			for (Field field : _group.getFields()) {
				bindings.add(new FormBinding(field, _form));
			}
			_bindings = bindings;
		}
		return _bindings;
	}
}
